﻿@{
    <div id="divztree" style="display:none">@ViewBag.ztreea</div>
    <div id="divrole" style="display:none">@ViewBag.role</div>
    Layout = null;
}
<html>
   <head>
   <style type="text/css" >
      fieldset {
    border: 1px solid #ddd;
    padding: 0 1.4em 1.4em 1.4em;
    margin: 0 0 1.5em 0;
}

legend {
    font-size: 1.2em;
    font-weight: bold;
}
   </style>
      <title></title>
       <link href="../../Content/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
       <link href="../../Content/css/demo.css" rel="stylesheet" type="text/css" />
       <link href="../../Scripts/PageCreater/Css/Style.css" rel="stylesheet" type="text/css" />
       <script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
       <script src="../../Scripts/jquery.ztree.core-3.5.js" type="text/javascript"></script>
       <script src="../../Scripts/PageCreater/Scripts/PageCreater.js" type="text/javascript"></script>
       <link href="../../Content/tab/css/style.css" rel="stylesheet" type="text/css" />
       <script src="../../Scripts/zTree/js/jquery.ztree.excheck-3.5.js" type="text/javascript"></script>
       <script type="text/javascript">
           var setting = {
               edit: {
                   enable: true,
                   showRemoveBtn: false,
                   showRenameBtn: false
               },
               data: {
                   simpleData: {
                       enable: true
                   }
               },
               callback: {
                   onClick: zTreeOnClick
               }
           };


           $(document).ready(function () {
               var date = $("#divztree").text();
               var zNodes = eval("(" + date + ")");
               $.fn.zTree.init($("#treeDemo"), setting, zNodes);
               $("#treeDemo").css("border", "0").css("height", "170").css("background-color", "#ffffff");
               $("#treeDemo1").css("border", "0").css("height", "170").css("background-color", "#ffffff");
               var str = "Account,账号,false,text,notnull,"
                             + "Name,姓名,false,text,notnull,"
                             + "IsActive,状态,false,select|激活!true|注销!false,notnull,"
                             + "Opreate,操作,false,null,null";
               CreatePageFram(str);
               var accounto = $("#Account");
               accounto.val("*格式：英文字符+数字").css("color", "red");
               accounto.focus(function () {
                   if (accounto.val() == "*格式：英文字符+数字") {
                       accounto.val("");
                       accounto.css("color", "#000000");
                   }
               })
               accounto.blur(function () {
                   if (accounto.val() == "") {
                       accounto.val("*格式：英文字符+数字").css("color", "red");
                   }
                   else {
                       accounto.css("color", "#000000");
                   }
               })
               $("#btnSubmit").click(function () {
                   var re = /^[A-Za-z0-9]+$/;
                   if (!re.test($("#Account").val())) {
                       alert("不能输入汉字和特殊字符");
                       $("#Account").focus();
                       return false;
                   }
                   if ($("#inputselected").attr("name") == "") {
                       alert("请选择机构");
                       $("#inputselected").focus();
                       return false;
                   }
                   if (clicks().length == 0) {
                       alert("请选择角色");
                       return false;
                   }
                   var rer = new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5]+$");
                   if (!rer.test($("#Name").val())) {
                       alert("只能输入纯中文名字或纯英文名");
                       return false;
                   }



                   var Account = $("#Account").val();
                   $.get("../User/getrepituser", { Account: Account }, function (data) {
                       if (parseInt(data) > 0) {
                           alert("用户名已存在");
                           $("#Account").focus();
                           return false;
                       }
                       else {
                           var Name = $("#Name").val();
                           var IsActive = $("#IsActive option:selected").val();
                           var juese = clicks();
                           var organ = $("#inputselected").attr("name");
                           $.get("../User/Creater", { roleIDs: juese, Account: Account, Name: Name, IsActive: IsActive, organ: organ }, function (data) {
                               if (parseInt(data) > 0) {
                                   window.location.href = location.protocol + "//" + location.host + "/User/Index";
                               }
                               else {
                                   alert("添加失败");
                               }
                           });
                       }
                   })
               });
               bindjuese();
           });
           function bindjuese() {
               var zn = $("#divrole").text();
               var zNodessss = eval("(" + zn + ")");
               $.fn.zTree.init($("#treeDemo1"), setting1, zNodessss);
               $("#treeDemo1").css("border", "0");
               setCheck();
           }

           function zTreeOnClick(event, treeId, treeNode) {
               $("#inputselected").val(treeNode.name);
               $("#inputselected").attr("name", treeNode.id);
               $("#inputselected").css("color", "#000000");
           }

           var setting1 = {
               check: {
                   enable: true
               },
               data: {
                   simpleData: {
                       enable: true
                   }
               },
               callback: {
                   onCheck: zTreeOnCheck
               }
           };
           function setCheck() {
               var zTree = $.fn.zTree.getZTreeObj("treeDemo1"),
			   type = { "Y": "", "N": "" };
               zTree.setting.check.chkboxType = type;
           }
           function clicks() {
               var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
               var nodes = treeObj.getCheckedNodes(true);
               var roles = "";
               for (var i = 0; i < nodes.length; i++) {
                   roles += nodes[i].id + ",";
               }
               roles = roles.substring(0, roles.length - 1);
               return roles;
           }

        
           function zTreeOnCheck(event, treeId, treeNode) {
               if (treeNode.name == "学生") {
                   var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
                   var nodes = treeObj.getCheckedNodes(false);
                   if (treeNode.checked) {
                       var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
                       var nodes1 = treeObj.getCheckedNodes(false);
                       for (var i = 0; i < nodes1.length; i++) {
                           treeObj.setChkDisabled(nodes1[i], true);
                       }
                   }
                   else {
                       bindjuese();
                   }
               }
               else {
                   var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
                   var node = treeObj.getNodeByParam("name", "学生", null);
                   treeObj.setChkDisabled(node, true);
               }
               var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
               var nodes = treeObj.getCheckedNodes(true);
               if (nodes == "") {
                   bindjuese();
               };
           };

       </script>
   </head>
   <body>
        <div>
            <br />
            <p>@Html.ActionLink("返回列表", "Index")</p>
            <br />
        </div>
        <fieldset>
     
           <legend>机构、用户信息填写</legend>
             <div>
                 <div style="float:left">
                      <span><b>基本信息</b></span>
                      <div id="divContent">
                      </div>
                      <div>
                         机构<input type="text" id="inputselected" value="*必填" readonly="readonly" name="" style="color:Red" />
                      </div>
                 </div>
                 <div style="float:left">
                        <span><b>机构选择</b></span>
                       <ul id="treeDemo" class="ztree" style="overflow: auto; height:300px"></ul>
                 </div>
                 <div style="float:left">
                        <span>
                            <b>角色选择</b>
                        </span>
		               <ul id="treeDemo1" class="ztree" style="overflow: auto; height:300px"></ul>
	             </div>
            </div>
        </fieldset>
    <center><input type="submit"  class="btn3" id="btnSubmit" value ="添加" /></center>  
      
   

   </body>
</html>
